﻿using GrapeCity.Forguncy.CellTypes;
using GrapeCity.Forguncy.Commands;
using GrapeCity.Forguncy.Plugin;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Vant.Commands
{

    [Icon("pack://application:,,,/ElementUI;component/Resources/Images/Notification.png")]
    [OrderWeight((int)OrderWeight.Dialog)]
    public class Dialog : VantCommandBase
    {
        [FormulaProperty]
        [SRDisplayName(nameof(Properties.Resources.Title))]
        public object title { get; set; }

        [FormulaProperty(AcceptsReturn = true)]
        [SRDisplayName(nameof(Properties.Resources.Content))]
        public object message { get; set; }

        [SRComboProperty(ValueList = "default|round-button", DisplayList = nameof(Properties.Resources.DialogThemeDisplayList))]
        [SRDisplayName(nameof(Properties.Resources.Theme))]
        public string theme { get; set; } = "default";

        [SRDisplayName(nameof(Properties.Resources.ShowConfirmButton))]
        [DefaultValue(true)]
        public bool showConfirmButton { get; set; } = true;

        [FormulaProperty]
        [SRDisplayName(nameof(Properties.Resources.Vant_ConfirmButtonText))]
        public object confirmButtonText { get; set; }
        [ColorProperty]
        [SRDisplayName(nameof(Properties.Resources.ConirmButtonColor))]
        public string confirmButtonColor { get; set; } = "Accent 1";

        [SRDisplayName(nameof(Properties.Resources.ShowCancelButton))]
        [DefaultValue(false)]
        public bool showCancelButton { get; set; } = false;
        [FormulaProperty]
        [SRDisplayName(nameof(Properties.Resources.Vant_CancelButtonText))]
        public object cancelButtonText { get; set; }
        [ColorProperty]
        [SRDisplayName(nameof(Properties.Resources.CancelButtonColor))]
        public string cancelButtonColor { get; set; } = "Text 1";

        [SRDisplayName(nameof(Properties.Resources.SaveDialogResultToVar))]
        [ResultToProperty]
        [SRDescription(nameof(Properties.Resources.SaveDialogResultToVarDescription))]
        public string DialogResult { get; set; }

        [ObjectProperty(ObjType = typeof(AdvancedSetting))]
        [SRDisplayName(nameof(Properties.Resources.AdvancedSetting))]
        public AdvancedSetting AdvancedSetting { get; set; } = new AdvancedSetting();

        public override bool GetDesignerPropertyVisible(string propertyName, CommandScope commandScope)
        {
            if(propertyName == nameof(confirmButtonText)||
                propertyName == nameof(confirmButtonColor))
            {
                return showConfirmButton;
            }
            if (propertyName == nameof(cancelButtonText) ||
                propertyName == nameof(cancelButtonColor))
            {
                return showCancelButton;
            }
            return base.GetDesignerPropertyVisible(propertyName, commandScope);
        }

        public override string ToString()
        {
            return Properties.Resources.Vant_Dialog;
        }

        public override void InitDefaultPropertyValues()
        {
            base.InitDefaultPropertyValues();
            this.title = Properties.Resources.Title;
            this.message = Properties.Resources.Content;
            this.confirmButtonText = Properties.Resources.Vant_Confirm;
            this.cancelButtonText = Properties.Resources.Vant_Cancel;
        }
    }

    public class AdvancedSetting: ObjectPropertyBase
    {
        [SRComboProperty(ValueList = "center|left|right", DisplayList = nameof(Properties.Resources.ContentAlignmentDisplayList))]
        [SRDisplayName(nameof(Properties.Resources.ContentAlignment))]
        public string messageAlign { get; set; } = "center";

        [IntProperty]
        [SRDisplayName(nameof(Properties.Resources.DialogWidth))]
        [DefaultValue(320)]
        public int width { get; set; } = 320;

        [SRDisplayName(nameof(Properties.Resources.Dialog_AllowHtml))]
        public bool allowHtml { get; set; }

        [SRDisplayName(nameof(Properties.Resources.ShowOverlay))]
        [DefaultValue(true)]
        public bool overlay { get; set; } = true;

        [SRDisplayName(nameof(Properties.Resources.CloseOnClickOverlay))]
        [DefaultValue(false)]
        public bool closeOnClickOverlay { get; set; } = false;

        [SRDisplayName(nameof(Properties.Resources.CloseOnPopstate))]
        [DefaultValue(true)]
        public bool closeOnPopstate { get; set; } = true;

        [BoolProperty]
        [DefaultValue(false)]
        [SRDisplayName(nameof(Properties.Resources.Dialog_DistinguishCancelAndClose))]
        [SRDescription(nameof(Properties.Resources.Dialog_DistinguishCancelAndClose_Description))]
        public bool distinguishCancelAndClose { get; set; } = false;

        public override bool GetDesignerPropertyVisible(string propertyName)
        {
            if (propertyName == nameof(closeOnClickOverlay)) {
                return overlay;
            }
            return base.GetDesignerPropertyVisible(propertyName);
        }
    }
}
